Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API: Add a 'published' video parameter for related videos #4149

Open
wants to merge 28 commits into
base: master
Choose a base branch
from

Conversation

RadoslavL
Copy link
Contributor

@RadoslavL RadoslavL commented Oct 7, 2023

This closes #3058.

It could also allow recommended videos to have their upload date shown on the /watch route. Let me know if you want me to add that as well.

Important thing to note - this way of adding the parameter wouldn't be very precise for old videos. New videos may show up as "1 hour ago" and when that happens, the date would be accurate to the hours. Old videos may show up as "1 year ago" and that would mean that the date would only be accurate to the years. The month and day would just be chosen to be the current time's month and day, so it wouldn't even be close. But without making more API requests I don't see how this can work more accurately.

@RadoslavL RadoslavL requested a review from a team as a code owner October 7, 2023 14:01
@RadoslavL RadoslavL requested review from unixfox and removed request for a team October 7, 2023 14:01
@absidue
Copy link
Contributor

absidue commented Oct 7, 2023

Please refactor this to query the database instead of making 20+ API requests every single time. Ideally parse the published date that is already in the watch next/recommended videos feed instead of making any extra requests. This current approach will get every instance, other than small ones, rate limited by YouTube very quickly, which will result in it being impossible to play videos at all on those instances.

@RadoslavL
Copy link
Contributor Author

Please refactor this to query the database instead of making 20+ API requests every single time. Ideally parse the published date that is already in the watch next/recommended videos feed instead of making any extra requests. This current approach will get every instance, other than small ones, rate limited by YouTube very quickly, which will result in it being impossible to play videos at all on those instances.

When I made this I thought that a couple of API calls wouldn't really matter, but now that I think about it, this is a very big problem. I can't get the published date from the related videos' info hash, because they only include the simpleText version. This means that it will show up as "1 hour ago" instead of "2023-10-07". Unless I can fetch the video data separately or compute it manually, I wouldn't be able to solve this issue. I will try parsing the date using the timezone data tomorrow. I will also make sure to use the database when possible. Thank you for the reply!

@SamantazFox SamantazFox marked this pull request as draft October 8, 2023 10:23
@RadoslavL
Copy link
Contributor Author

I removed the need for more API calls, but keep in mind that this method wouldn't be very precise. If the video is an hour or a day old, the date would be right, but if it is a year old, it might be off by months.

@RadoslavL RadoslavL marked this pull request as ready for review October 9, 2023 09:13
@RadoslavL RadoslavL changed the title Added a 'published' video parameter for related videos Add a 'published' video parameter for related videos Oct 31, 2023
@RadoslavL RadoslavL changed the title Add a 'published' video parameter for related videos API: Add a 'published' video parameter for related videos Oct 31, 2023
src/invidious/videos/parser.cr Outdated Show resolved Hide resolved
src/invidious/videos/parser.cr Outdated Show resolved Hide resolved
src/invidious/videos/parser.cr Outdated Show resolved Hide resolved
src/invidious/videos/parser.cr Outdated Show resolved Hide resolved
Copy link
Member

@syeopite syeopite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple more nitpicks

src/invidious/videos/parser.cr Outdated Show resolved Hide resolved
src/invidious/videos/parser.cr Outdated Show resolved Hide resolved
src/invidious/videos/parser.cr Outdated Show resolved Hide resolved
src/invidious/videos/parser.cr Outdated Show resolved Hide resolved
@RadoslavL
Copy link
Contributor Author

RadoslavL commented Jan 7, 2024

Bump. This PR seems to have been forgotten.

@ashley0143
Copy link

doesnt work after the new youtube update

@@ -245,6 +245,8 @@ module Invidious::JSONify::APIv1
json.field "lengthSeconds", rv["length_seconds"]?.try &.to_i
json.field "viewCountText", rv["short_view_count"]?
json.field "viewCount", rv["view_count"]?.try &.empty? ? nil : rv["view_count"].to_i64
json.field "published", rv["published"]?
json.field "publishedTimeText", translate(locale, "`x` ago", rv["publishedText"].to_s.gsub(" ago", ""))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things here:

  1. The JSON field should be publishedText, to match the rest of the API
  2. The text should be translated from the time we parsed earlier. The text from the innertube (internal Youtube) API is always in english, and can't be used directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had trouble fully understanding the second request, but I improved my old code. I thought about using Time.unix(0) when rv[published] was nil, but decided to make it more obvious that something is wrong, when it happens.

I also greatly apologize for the 3 month delay! I took a very long break, because of personal issues in my life.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also greatly apologize for the 3 month delay! I took a very long break, because of personal issues in my life.

No problem :) Your life is much more important than anything else!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for saying that :)

src/invidious/videos/parser.cr Outdated Show resolved Hide resolved
Copy link

github-actions bot commented Aug 9, 2024

This pull request has been automatically marked as stale and will be closed in 30 days because it has not had recent activity and is much likely abandoned or outdated. If you think this pull request is still relevant and applicable, you just have to post a comment and it will be unmarked.

@github-actions github-actions bot added the stale label Aug 9, 2024
@syeopite syeopite removed the stale label Aug 9, 2024
@SamantazFox SamantazFox added the need-testing This feature needs to be deployed and tested to see if it's working, and doesn't break something label Oct 31, 2024
@SamantazFox SamantazFox added in-testing This feature has been deployed and is being tested and removed need-testing This feature needs to be deployed and tested to see if it's working, and doesn't break something labels Nov 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in-testing This feature has been deployed and is being tested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Enhancement] API /api/v1/videos/:id - Return published for recommendedVideos
5 participants